//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //---------------------------- Ebrahim Foulaadvand, 10 July 2013 ----------------- // // // // The routine "AdvectionLax" solves the 1D wave equation using the Lax and Lax-Wendroff methods. // // Periodic boundary condition is used. The system length L and the wave velocity c are set to one. // // Initial wave shape is cosine-modulated Gaussian pulse. // // // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include using namespace std; main() { double tau=0.004,h,L=1,c=1,sigma=0.05,lambda=0.2,k=2*M_PI/lambda,x; int N=200,i,n,T=1000; ofstream file0 ("initial profile n=0.plt"); //output file for the profile at timestep n=0. ofstream file1 ("profile Lax n=20.plt"); //output file for the profile at timestep n=100. ofstream file2 ("profile Lax n=40.plt"); //output file for the profile at timestep n=500. ofstream file3 ("profile Lax n=100.plt"); //output file for the profile at timestep n=500. ofstream file4 ("profile LW n=20.plt"); //output file for the profile at timestep n=500. ofstream file5 ("profile LW n=40.plt"); //output file for the profile at timestep n=500. ofstream file6 ("profile LW n=100.plt"); //output file for the profile at timestep n=500. vector u(N+1,0),unew(N+1,0),uL(N+1,0),uLnew(N+1,0),uLW(N+1,0),uLWnew(N+1,0); // Arrays "u" and "unew" store the current and updated values // of the scaler function u(x,t) at grid points. "L" stands for Lax and "LW" stands for Lax-Wendroff. h=L/N; cout<<"h= "<